home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / exampleCode / opengl / GLUT / lib / fglut / fglut.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-11  |  6.8 KB  |  320 lines

  1.  
  2. /* Copyright (c) Mark J. Kilgard, 1994. */
  3.  
  4. /* This program is freely distributable without licensing fees
  5.    and is provided without guarantee or warrantee expressed or
  6.    implied. This program is -not- in the public domain. */
  7.  
  8. #ifndef WRAPPERS_ONLY
  9.  
  10. #include <glutint.h>
  11.  
  12. extern int __Argc;
  13. extern char **__Argv;
  14.  
  15. static GLUTmenuStateFCB fortranMenuStateFunc;
  16.  
  17. void
  18. glutnull_(void)
  19. {
  20. }
  21.  
  22. void
  23. glutinit_(void)
  24. {
  25.   glutInit(&__Argc, __Argv);
  26. }
  27.  
  28. static void
  29. fortranMenuStateWrapper(int value)
  30. {
  31.   fortranMenuStateFunc(&value);
  32. }
  33.  
  34. static void
  35. fortranReshapeWrapper(int w, int h)
  36. {
  37.   (*__glutCurrentWindow->freshape) (&w, &h);
  38. }
  39.  
  40. static void
  41. fortranKeyboardWrapper(unsigned char ch, int x, int y)
  42. {
  43.   int chi = ch;
  44.  
  45.   (*__glutCurrentWindow->fkeyboard) (&chi, &x, &y);
  46. }
  47.  
  48. static void
  49. fortranMouseWrapper(int btn, int state, int x, int y)
  50. {
  51.   (*__glutCurrentWindow->fmouse) (&btn, &state, &x, &y);
  52. }
  53.  
  54. static void
  55. fortranMotionWrapper(int x, int y)
  56. {
  57.   (*__glutCurrentWindow->fmotion) (&x, &y);
  58. }
  59.  
  60. static void
  61. fortranPassiveMotionWrapper(int x, int y)
  62. {
  63.   (*__glutCurrentWindow->fpassive) (&x, &y);
  64. }
  65.  
  66. static void
  67. fortranEntryWrapper(int state)
  68. {
  69.   (*__glutCurrentWindow->fentry) (&state);
  70. }
  71.  
  72. static void
  73. fortranVisibilityWrapper(int state)
  74. {
  75.   (*__glutCurrentWindow->fvisibility) (&state);
  76. }
  77.  
  78. static void
  79. fortranTimerWrapper(int value)
  80. {
  81.   /* relies on special knowledge that __glutTimerList points to 
  82.      the GLUTtimer* currently being processed! */
  83.   (*__glutTimerList->ffunc) (&value);
  84. }
  85.  
  86. static void
  87. fortranSelectWrapper(int value)
  88. {
  89.   (*__glutItemSelected->menu->fselect) (&value);
  90. }
  91.  
  92. static void
  93. fortranSpecialWrapper(int key, int x, int y)
  94. {
  95.   (*__glutCurrentWindow->fspecial) (&key, &x, &y);
  96. }
  97.  
  98. static void
  99. fortranSpaceballMotionWrapper(int x, int y, int z)
  100. {
  101.   (*__glutCurrentWindow->fspaceMotion) (&x, &y, &z);
  102. }
  103.  
  104. static void
  105. fortranSpaceballRotateWrapper(int x, int y, int z)
  106. {
  107.   (*__glutCurrentWindow->fspaceRotate) (&x, &y, &z);
  108. }
  109.  
  110. static void
  111. fortranSpaceballButtonWrapper(int button, int state)
  112. {
  113.   (*__glutCurrentWindow->fspaceButton) (&button, &state);
  114. }
  115.  
  116. static void
  117. fortranTabletMotionWrapper(int x, int y)
  118. {
  119.   (*__glutCurrentWindow->ftabletMotion) (&x, &y);
  120. }
  121.  
  122. static void
  123. fortranTabletButtonWrapper(int button, int state, int x, int y)
  124. {
  125.   (*__glutCurrentWindow->ftabletButton) (&button, &state, &x, &y);
  126. }
  127.  
  128. static void
  129. fortranDialsWrapper(int dial, int value)
  130. {
  131.   (*__glutCurrentWindow->fdials) (&dial, &value);
  132. }
  133.  
  134. static void
  135. fortranButtonBoxWrapper(int button, int state)
  136. {
  137.   (*__glutCurrentWindow->fbuttonBox) (&button, &state);
  138. }
  139.  
  140. #endif /* WRAPPERS_ONLY */
  141.  
  142. #define glutfunc(Name,name) \
  143. void \
  144. glut##name##func(GLUT##name##FCB name) \
  145. { \
  146.     if(name == (GLUT##name ## FCB) glutnull_) { \
  147.     glut##Name ## Func(NULL); \
  148.     } else { \
  149.     glut ## Name ## Func(fortran ## Name ## Wrapper); \
  150.     __glutCurrentWindow->f ## name = name; \
  151.     } \
  152. }
  153.  
  154. glutfunc(Reshape, reshape)
  155. glutfunc(Keyboard, keyboard)
  156. glutfunc(Mouse, mouse)
  157. glutfunc(Motion, motion)
  158. glutfunc(Entry, entry)
  159. glutfunc(Visibility, visibility)
  160. glutfunc(Special, special)
  161. glutfunc(Dials, dials)
  162.  
  163. /* special callback cases */
  164.  
  165. /* The display has no parameters passed so no need for wrapper. */
  166. void
  167. glutdisplayfunc(GLUTdisplayFCB display)
  168. {
  169.   glutDisplayFunc((GLUTdisplayCB) display);
  170. }
  171.  
  172. void
  173. glutpassivemotionfunc(GLUTpassiveFCB passive)
  174. {
  175.   if (passive == (GLUTpassiveFCB) glutnull_) {
  176.     glutPassiveMotionFunc(NULL);
  177.   } else {
  178.     glutPassiveMotionFunc(fortranPassiveMotionWrapper);
  179.     __glutCurrentWindow->fpassive = passive;
  180.   }
  181. }
  182.  
  183. void
  184. glutspacemotionfunc(GLUTspaceMotionFCB spaceMotion)
  185. {
  186.   if (spaceMotion == (GLUTspaceMotionFCB) glutnull_) {
  187.     glutSpaceballMotionFunc(NULL);
  188.   } else {
  189.     glutSpaceballMotionFunc(fortranSpaceballMotionWrapper);
  190.     __glutCurrentWindow->fspaceMotion = spaceMotion;
  191.   }
  192. }
  193.  
  194. void
  195. glutspacerotatefunc(GLUTspaceRotateFCB spaceRotate)
  196. {
  197.   if (spaceRotate == (GLUTspaceRotateFCB) glutnull_) {
  198.     glutSpaceballRotateFunc(NULL);
  199.   } else {
  200.     glutSpaceballRotateFunc(fortranSpaceballRotateWrapper);
  201.     __glutCurrentWindow->fspaceRotate = spaceRotate;
  202.   }
  203. }
  204.  
  205. void
  206. glutspacebuttonfunc(GLUTspaceButtonFCB spaceButton)
  207. {
  208.   if (spaceButton == (GLUTspaceButtonFCB) glutnull_) {
  209.     glutSpaceballButtonFunc(NULL);
  210.   } else {
  211.     glutSpaceballButtonFunc(fortranSpaceballButtonWrapper);
  212.     __glutCurrentWindow->fspaceButton = spaceButton;
  213.   }
  214. }
  215.  
  216. void
  217. glutbuttonboxfunc(GLUTbuttonBoxFCB buttonBox)
  218. {
  219.   if (buttonBox == (GLUTbuttonBoxFCB) glutnull_) {
  220.     glutButtonBoxFunc(NULL);
  221.   } else {
  222.     glutButtonBoxFunc(fortranButtonBoxWrapper);
  223.     __glutCurrentWindow->fbuttonBox = buttonBox;
  224.   }
  225. }
  226.  
  227. void
  228. gluttabletmotionfunc(GLUTtabletMotionFCB tabletMotion)
  229. {
  230.   if (tabletMotion == (GLUTtabletMotionFCB) glutnull_) {
  231.     glutTabletMotionFunc(NULL);
  232.   } else {
  233.     glutTabletMotionFunc(fortranTabletMotionWrapper);
  234.     __glutCurrentWindow->ftabletMotion = tabletMotion;
  235.   }
  236. }
  237.  
  238. void
  239. gluttabletbuttonfunc(GLUTtabletButtonFCB tabletButton)
  240. {
  241.   if (tabletButton == (GLUTtabletButtonFCB) glutnull_) {
  242.     glutTabletButtonFunc(NULL);
  243.   } else {
  244.     glutTabletButtonFunc(fortranTabletButtonWrapper);
  245.     __glutCurrentWindow->ftabletButton = tabletButton;
  246.   }
  247. }
  248.  
  249. int
  250. glutcreatemenu(GLUTselectFCB selectFunc)
  251. {
  252.   int menu;
  253.  
  254.   menu = glutCreateMenu(fortranSelectWrapper);
  255.   __glutCurrentMenu->fselect = selectFunc;
  256.   return menu;
  257. }
  258.  
  259. void
  260. gluttimerfunc(unsigned long interval, GLUTtimerFCB timerFunc, int value)
  261. {
  262.   glutTimerFunc(interval, fortranTimerWrapper, value);
  263.   /* relies on special __glutNewTimer variable side effect to
  264.      establish Fortran timer func! */
  265.   __glutNewTimer->ffunc = timerFunc;
  266. }
  267.  
  268. void
  269. glutidlefunc(GLUTidleFCB idleFunc)
  270. {
  271.   if (idleFunc == (GLUTidleFCB) glutnull_) {
  272.     glutIdleFunc(NULL);
  273.   } else {
  274.     glutIdleFunc(idleFunc);
  275.   }
  276. }
  277.  
  278. void
  279. glutmenustatefunc(GLUTmenuStateFCB menuStateFunc)
  280. {
  281.   if (menuStateFunc == (GLUTmenuStateFCB) glutnull_) {
  282.     glutMenuStateFunc(NULL);
  283.   } else {
  284.     glutMenuStateFunc(fortranMenuStateWrapper);
  285.     fortranMenuStateFunc = menuStateFunc;
  286.   }
  287. }
  288.  
  289. void
  290. glutbitmapcharacter(int *font, int ch)
  291. {
  292.   /* 
  293.    * mkf2c gets confused by double pointers and void* pointers.
  294.    * So mkf2c does not complain, we consider the font handle to
  295.    * be an int*.  But we really get an int** since Fortran
  296.    * passes by reference.  So to "pedantically decode" the 
  297.    * pointer, cast it first to int**, then dereference it,
  298.    * then cast the result to a void*.
  299.    */
  300.   void *trueFont = (void *) *((int **) font);
  301.  
  302.   glutBitmapCharacter(trueFont, ch);
  303. }
  304.  
  305. void
  306. glutstrokecharacter(int *font, int ch)
  307. {
  308.   /* 
  309.    * mkf2c gets confused by double pointers and void* pointers.
  310.    * So mkf2c does not complain, we consider the font handle to
  311.    * be an int*.  But we really get an int** since Fortran
  312.    * passes by reference.  So to "pedantically decode" the 
  313.    * pointer, cast it first to int**, then dereference it,
  314.    * then cast the result to a void*.
  315.    */
  316.   void *trueFont = (void *) *((int **) font);
  317.  
  318.   glutStrokeCharacter(trueFont, ch);
  319. }
  320.